﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class WebCommon_DisplaySource : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }

    void Bind()
    {
        int PlanId = Utility.HttpHelp.getParamsInt("PlanId");
        string type = Utility.HttpHelp.getParamsString("type");
        switch (type)
        {
            case "Quarter":
                BindStrategicPlan(PlanId);
                break;
            case "Month":
                BindQuarterPlan(PlanId);
                break;
            case "Week":
                BindMonthPlan(PlanId);
                break;
            default:
                break;
        }
    }

    DataTable BindStrategicPlan(int StrategicPlanId)
    {
        string sql = @"select * from DS_StrategicPlan where StrategicPlanId = " + StrategicPlanId;
        DataTable dt = DAL.SqlHelper.ExecuteDataset(DAL.SqlHelper.connStr, System.Data.CommandType.Text, sql).Tables[0];
        this.gdvStrategicPlan.DataSource = dt;
        this.gdvStrategicPlan.DataBind();
        if (dt.Rows.Count > 0)
        {
            this.lblStrategicPlan.Visible = true;
        }

        return dt;
    }

    DataTable BindQuarterPlan(int QuarterPlanId)
    {
        string sql = @"select * from DS_QuarterPlan where QuarterPlanId = " + QuarterPlanId;
        DataTable dt = DAL.SqlHelper.ExecuteDataset(DAL.SqlHelper.connStr, System.Data.CommandType.Text, sql).Tables[0];
        this.gdvQuarterPlan.DataSource = dt;
        this.gdvQuarterPlan.DataBind();
        if (dt.Rows.Count > 0)
        {
            this.lblQuarter.Visible = true;
            int StrategicPlanId = Convert.ToInt32(dt.Rows[0]["StrategicPlanId"]);
            DataTable dt_strategic = BindStrategicPlan(StrategicPlanId);
            this.gdvStrategicPlan.DataSource = dt_strategic;
            this.gdvStrategicPlan.DataBind();
            if (dt_strategic.Rows.Count > 0)
            {
                this.lblStrategicPlan.Visible = true;
            }
        }
        return dt;
    }

    DataTable BindMonthPlan(int MonthPlanId)
    {
        string sql = @"select * from DS_MonthPlan where MonthPlanId = " + MonthPlanId;
        DataTable dt = DAL.SqlHelper.ExecuteDataset(DAL.SqlHelper.connStr, System.Data.CommandType.Text, sql).Tables[0];
        this.gdvMonthPlan.DataSource = dt;
        this.gdvMonthPlan.DataBind();
        if (dt.Rows.Count > 0)
        {
            this.lblMonthPlan.Visible = true;
            int QuarterPlanId = Convert.ToInt32(dt.Rows[0]["QuarterPlanId"]);
            DataTable dt_quarter = BindQuarterPlan(QuarterPlanId);

            if (dt_quarter.Rows.Count > 0)
            {
                this.lblQuarter.Visible = true;
                int StrategicPlanId = Convert.ToInt32(dt_quarter.Rows[0]["StrategicPlanId"]);
                DataTable dt_Strategic = BindStrategicPlan(StrategicPlanId);
                if (dt_Strategic.Rows.Count > 0)
                {
                    this.lblStrategicPlan.Visible = true;
                }
            }
        }
        return dt;
    }

}